/**
 *
 */

var app = getApp()
Page({
	data: {
		root: app.setting.att_url,
		banner: [],
		goods: [],
		page:1,
		pagedata:[],
		pagetitle:'表单记录',
		bannerHeight: Math.ceil(290.0 / 750.0 * getApp().screenWidth)
	},
	onPullDownRefresh: function (){
		var the=this;
		var opt={};
		the.onLoad(opt);
		setTimeout(function(){
			wx.stopPullDownRefresh()
		},1000);
	},
	onLoad: function (opt){
		var the = this
		wx.setNavigationBarTitle({'title':the.data.pagetitle});
		var route=the.route;
		the.setData({
			route:route,
		});
		//console.log('opt');console.log(opt);
		if(opt && (opt.id || opt.fromuser)){
			var path=route.slice(0,-6).split('/');
			app.access.plugin=path.shift();
			app.access.action=path.join('.');
			app.access.query =app.util.made_query(opt,true);
			if(opt.id){
				opt.op='detail';
			}
			app.access.op=opt.op?opt.op:'';
		}
		if(opt && opt.isgoshare){
				the.setData({
					ShowGoshare:true,
				});
		}
		app.util.get(app.access,function(pagedata){
			pagedata.params=pagedata.params?pagedata.params:{}
			pagedata.params.status=pagedata.status;
			console.log(pagedata);
			the.setData({
				pagedata:pagedata,
				loading:false
			});
			the.getlist(1);
		});
	},
	//翻页
	onReachBottom: function () {
		var isnodata=this.data.isnodata
		var loading=this.data.loading
		if(!isnodata && !loading){
			this.getlist()
		}
	},
	getlist: function(e){
		var the = this
		var isnodata = the.data.isnodata;
		var page = the.data.page;
		var pagedata = the.data.pagedata;
		if(e){
			if(e.currentTarget){
				var data=e.currentTarget.dataset;
				if(data.status || data.status==0){
					pagedata.params.status=data.status;
				}
			}
			page = 1;
			pagedata.list=[];
			isnodata=false;
		}else{
			if(isnodata){
				return false;
			}
		}
		var query='page='+page;
		var more_query=app.util.made_query(pagedata.params);
		if(more_query){
			query+='&'+more_query;
		}
		app.util.get('core/member.diyform/list/'+query,function(res){
			//console.log('2121');console.log(res);
			//加载分页
			if(res.list.length>0){
					pagedata.list = pagedata.list.concat(res.list);
					if(page >1){
						$(".goods-item").animate({scrollTop:0},300);
					}
					page++;
			}else{
					isnodata = true
			}
			the.setData({
				'pagedata.list':pagedata.list,
				'pagedata.params':pagedata.params,
				page:page,
				isnodata:isnodata,
				loading:false
			});
		});
	},
	click:function(evt){
		//用户点击事件 data.func 为方法名，data.params 为调用参数！
		var data=evt.currentTarget.dataset;
		//console.log(evt);
		app.util[data.func](data.params);
	},
})